package io.zhifei.modules.sys.pr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.zhifei.modules.sys.pr.entity.Asset;
import io.zhifei.modules.sys.pr.mapper.AssetMapper;
import io.zhifei.modules.sys.pr.model.params.AssetParam;
import io.zhifei.modules.sys.pr.model.vo.AssetVO;
import io.zhifei.modules.sys.pr.service.AssetService;
import io.zhifei.modules.sys.pr.util.ForestNodeMerger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 资产表 服务实现类
 * </p>
 *
 * @author qdp
 * @since 2021-08-09
 */
@Service
public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements AssetService {

    @Override
    public Integer add(Asset xxlJobInfo) {
        return this.baseMapper.insert(xxlJobInfo);
    }

    @Override
    @Transactional
    public boolean addAsset(AssetParam assetParam) {
        return this.saveOrUpdate(assetParam);
    }

    @Override
    public IPage<AssetParam> listPage(IPage<Asset> page, QueryWrapper<Asset> qw) {
        return this.baseMapper.scheduPage(page, qw);
    }

    @Override
    public List<AssetVO> tree() {
        return ForestNodeMerger.merge(baseMapper.tree());
    }
}
